package com.wu.util.spider;

import org.junit.jupiter.api.Test;

import javax.script.*;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class test {
    @Test
    public void test1() throws FileNotFoundException, ScriptException, NoSuchMethodException {
        ScriptEngine se = new ScriptEngineManager().getEngineByName("javascript");
//        Bindings bindings = se.createBindings();
//        bindings.put("name", "wu");
        se.eval(new FileReader("K:\\develop\\java\\spider\\src\\test\\java\\com\\wu\\util\\spider\\a.js"));
//        se.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        if (se instanceof Invocable) {
            Invocable in = (Invocable) se;
            String result = (String) in.invokeFunction("fun","wu");
            System.out.println("获得的结果：" + result);
        }
    }
}
